var url_TeacherData = basePath + "teacher/getTeacherData";
var tblCenter;
var teacherName;
$(function () {
    tblCenter = $('#tbl-center').DataTable(buildCenterOptions());
    trCssEvent(tblCenter);
    $("#btn-search-center").click(centerSearch);
    getTeacher();
});


function buildCenterOptions() {
    var options = {
        "searching": false,
        "ordering": true,
        "processing": true,
        "language": {
            "url": plugPath + 'DataTables/chinese.json'
        },
        "serverSide": true,
        "ajax": {
            "url": basePath + "teacher/getdata",
            "type": 'POST',
            data: function (params) {
                params['centerName'] = $("#centerName").val();
                params['teacherName'] = $("#teacher-name").val();
            }
        },

        "columns": [{
            "data": "centerName"
        }, {
            "data": "teacherName"
        }, {}],
        columnDefs: [{
            "targets": [2],
            "data": "teacherId",
            "render": function (data, type, row, meta, full) {
                    return "<a href='goStudentPage?teacherId="+data+"' target='_blank' >【查看该教师的学生信息】</a>";

                // return '<a href="#" onclick="window.open(\"'+basePath+'\")">【查看该教师的学生信息】</a>';

            }
        }],

        "dom" : "<'row'<'col-xs-12't>><'row'<'col-xs-2 lstyle'l><'col-xs-3'i><'col-xs-6  fright'p>>"
        
    };
    return options;
}


//查询搜索中心
function centerSearch() {
    $("#btn-search-center").attr("disabled", "disabled");
    tblCenter.ajax.reload(function () {
        $("#btn-search-center").removeAttr("disabled");
    });
}

//跳转的孩子的页面
function student(data) {
    var url = basePath + "teacher/goStudentPage";
    $("#center-modal").load(url, {
        teacherName: data
    }, function () {
    });
}


// 老师名字模糊提示
function getTeacher() {
    var techerData = [];
    $.ajax({
        url: url_TeacherData,
        data: {},
        type: "post",
        success: function (pm) {
            if (pm != null) {
                var techerDatas = [];
                techerData = pm.data;
                var dataLength = techerData.length;
                for (var i = 0; i < dataLength; i++) {
                    var centerName = techerData[i].centerName;
                    var teacherName = techerData[i].teacherName;
                    var tamp = teacherName + "中心:　" + centerName ;
                    var obj ;
                    obj = {label: tamp, value: teacherName};
                    techerDatas.push(obj);
                }
                doSelectTeacher(techerDatas);
            } else {
                alert("获取基本信息异常,请联系管理员");
            }
        }
    })
}


function doSelectTeacher(data) {
        $("#teacher-name").autocomplete({
        source: data,
        select: function (event, ui) {
            teacherName = ui.item.teacherName;
        }
    });
}

function queryCenter(data) {
    console.log(data.val);
}